#!/usr/bin/perl
# 2014/01/07 Align for Capillarysequence result

use strict;
use warnings;
use IO::File;
use Getopt::Std;
use File::Basename;
use Carp qw(croak);
$| = 0;

#---------------------------------------
# FIX parameter
#---------------------------------------
my $LENGTH = 25;	# length of each reads
my $FILE_reference = "/usr/local/biology/bwa-0.6.2/pombe.ASM294v2.19";	# reference for BWA

my $FILE_fastq1 = 'left.fasta';
my $FILE_fastq2 = 'right.fasta';
my $FILE_sai1 = 'left.sai';
my $FILE_sai2 = 'right.sai';
my $FILE_alnLog1 = 'left_aln.log';
my $FILE_alnLog2 = 'right_aln.log';
my $FILE_sam1 = 'left.sam';
my $FILE_sam2 = 'right.sam';
my $FILE_samLog1 = 'left_sam.log';
my $FILE_samLog2 = 'right_sam.log';

#---------------------------------------
# aln
#---------------------------------------
unless(-f $FILE_sai1){
	system("bwa aln  $FILE_reference $FILE_fastq1 > $FILE_sai1 2> $FILE_alnLog1") == 0 or die "aln command failed: $!";
}
unless(-f $FILE_sai2){
	system("bwa aln  $FILE_reference $FILE_fastq2 > $FILE_sai2 2> $FILE_alnLog2") == 0 or die "aln command failed: $!";
}

#---------------------------------------
# samse
#---------------------------------------
unless(-f $FILE_sam1){
	system("bwa samse -n 100 $FILE_reference $FILE_sai1 $FILE_fastq1 > $FILE_sam1 2> $FILE_samLog1") == 0 or die "samse command failed: $!";
}
unless(-f $FILE_sam2){
	system("bwa samse -n 100 $FILE_reference $FILE_sai2 $FILE_fastq2 > $FILE_sam2 2> $FILE_samLog2") == 0 or die "samse command failed: $!";
}



